package com.lh.unit;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author 梁昊
 * @date 2018/10/23
 * @function
 * @editLog
 */
@Component
public class CheckAccessTokenClass {
    @Autowired
    RedisOperator redisOperator;
//    @Autowired
//    MyTokenService myTokenService;

    /**
     * 从Redis中验证token
     *
     * @param clientType  客户端类型 BS或CS等
     * @param useId
     * @param useType
     * @param accessToken
     * @return
     */
    public boolean checkUseToken(String systemId, String clientType, String useId, String useType, String accessToken) {
        String keyName = String.format("%s%s%s:%s", systemId, clientType, useType, useId);
        String nowAccessToken = redisOperator.getString(keyName);
        if (nowAccessToken != null) {
            return nowAccessToken.equals(accessToken);
        } else
            return false;
//        return true;
//        MyTokenSelectInParam myTokenSelectInParam = new MyTokenSelectInParam();
//        myTokenSelectInParam.setUseId(useId);
//        myTokenSelectInParam.setUseType(useType);
//        myTokenSelectInParam.setClientType(clientType);
//        myTokenSelectInParam.setAccessToken(accessToken);
//        String selectToken = myTokenService.selectToken(myTokenSelectInParam);
//        if (selectToken == null)
//            return false;
//        else
//            return true;
    }

}
